' ##############################################################################
' Rapid-Q & SQLite3 (0.2 - freeware), March 5. 2005, Author: Slavo (iss@post.sk)
' Program is very simply, without any graphics and RAPIDQ.INC(!) etc. Must work!
' Requirement: this file, "frm.bas", "sqlite3.bas", "state1.bas" & "sqlite3.dll"
' You can download library "sqlite3.dll" on http://www.sqlite.org/download.html
' ##############################################################################

	$typecheck on
	application.title = "States"
	const crlf = chr$(13)

	' global declarations
	declare Function SetWindowLong LIB "User32" ALIAS "SetWindowLongA" (hwnd AS _
		Long, nIndex AS Long, dwNewLong AS Long) AS LONG ' minimalize correction
	declare Function SetFocus Lib "user32" Alias "SetFocus" (hwnd As Long) As Long
	' subs declarations
	declare sub frmStates_OnClose (action as integer)
	declare sub frmStates_OnShow
	declare sub btnStatesAdd_OnClick
	declare sub btnStatesUpdate_OnClick
	declare sub btnStatesDelete_OnClick
	declare sub lviStates_onChange
	declare sub lviStates_onKeyPress (key as Byte)
	declare sub cbxStatesOrder_OnChange
	declare sub ediStateName_onKeyUp (Key as Word)
	declare sub ediStateCode_onKeyUp (Key as Word)
	declare sub FillItemsFromTable (Sender as QStringList)

	' ----- my own SQLite3 functions for better manipulating with data ---------
	declare function SQL3_libversion as String
	declare function SQL3_gettable (sql_cmd as String, separ as String) as String
	declare function SQL3_errcode (error as word) as String

	' File "SQLite3.dll" must be in the same directory like this file
	$Resource library as "sqlite3.dll"
	If FileExists ("sqlite3.dll") = 0 then
		ShowMessage "Program is running the first time (maybe)." + chr$(13) + _
			"The library SQLite3.dll is missing - I create new..."
		ExtractResource Resource(0), "sqlite3.dll"
		If FileExists ("sqlite3.dll") = 0 then
			ShowMessage "The error occurs on extracting new library SQLite3.dll." + chr$(13) + _
				"Maybe read-only access to disc,  full disc etc."
				END
		else: ShowMessage "SQLite3.dll library extracts successfull."
		end if
	end If

' ##############################################################################
' Components
' ##############################################################################
	dim frmStates as QForm, pnlStates as QPanel, stbStates as QStatusBar
	dim btnStatesAdd as QCoolBtn
	dim btnStatesUpdate as QCoolBtn
	dim btnStatesDelete as QCoolBtn
	dim gbxStatesOrder as QGroupBox
	dim cbxStatesOrder as QComboBox
	dim lviStates as QListView

	dim frmState1 		as QForm
	dim btnStatOK 		as QButton, btnStatCancel 	as QButton
	dim lblStateName 	as QLabel, ediStateName 	as QEdit
	dim lblStateCode 	as QLabel, ediStateCode 	as QEdit

	dim filename 	as string
	dim db 			as long
	dim separ as String
		separ = "|" ' you can change it (e.g. separ ";" is good for QStringGrid)

' ##############################################################################
' Includes
' ##############################################################################
	$include "sqlite3.bas"	' separately list of SQLite3 commands and functions
	$include "frm.bas"		' main form with its components and subs
	$include "state1.bas"	' subform for manipulating with 1 record (add, update)

' ##############################################################################
' Others
' ##############################################################################
	frmStates.ShowModal
